import { defineStore } from 'pinia'
import { cloneDeep, uniqBy, filter } from 'lodash'

export const controlStore = defineStore('control', {
    state: () => {
        return {
            clientWidth: 0,
            clientHeight: 0,
            offTop: 0,
            language: sessionStorage.getItem('language') || 1, // 1 en  2 zh      ENG,CHN
            langList: [] // 保存后端传的  lang对应列表
        }
    },
    getters: {
        // getterLangList: (state) => {
        //     return state.langList || []
        // }
    },
    actions: {
        setClient(par) {
            this.clientWidth = par.clientWidth;
            this.clientHeight = par.clientHeight;
        },
        setOfftop(p) {
            this.offTop = p || 0;
        },
        setLangList(arr) {
            let list = cloneDeep(this.langList);
            list = list.concat(arr);
            list = uniqBy(list, 'id');
            this.langList = list;
        },
        setLang(p) {
            this.language = p || 1;
            sessionStorage.setItem('language', this.language)
        },
    },
})
 